//
//  FHPickerviewController.swift
//  SWfanghu
//
//  Created by 赵宇桥 on 16/6/8.
//  Copyright © 2016年 ly. All rights reserved.
//

import Foundation
import UIKit

class FHPickerviewController: UIView, UIPickerViewDelegate,UIPickerViewDataSource {
    // MAKRK: property
    
    var rowtitle = ["北京","北京","北京","北京","北京"]
    var frameSize = CGRect(x: 0, y: 0, width: 640, height: 1136)

    lazy var whiteView:UIView = {
        let white = UIView()
        white.backgroundColor = UIColor.whiteColor()
        return white
    }()
    
    lazy var closeBT:UIButton = {
        let close = UIButton(ImageNamed: "guanbi.png", BackgroundImageName: "guanbi.png")
        return close
    }()
    
    lazy var titleLabel:UILabel = {
        let title = UILabel(labText: "城市", textSize: UIFont.systemFontOfSize(14), labTextColor: UIColor.blackColor())
        title.textAlignment = .Center
        return title
    }()
    
    lazy var okBT:UIButton = {
        let ok = UIButton(title: "完成", backImageName: "", titleColoe: UIColor.whiteColor())
        ok.layer.cornerRadius = 5
        ok.backgroundColor = color_import_red
        return ok
    }()
    
    lazy var pickerView:UIPickerView = {
        let pick = UIPickerView()
        return pick
    }()
    
    // MARK: -
    override init(frame: CGRect) {
        super.init(frame: frame)
           
        backgroundColor = UIColor(colorLiteralRed: 0, green: 0, blue: 0, alpha: 0.3)
        backgroundColor = UIColor.redColor()
        whiteView.frame = CADipRectMake(0, frameSize.height-300, frameSize.width, 300)
        
        addSubview(whiteView)
        
        closeBT.frame = CADipRectMake(spaceHeight, (88-50)/2, 50, 50)
        closeBT.addTarget(self, action: #selector(FHPickerviewController.buttonClick(_:)), forControlEvents: .TouchUpInside)
        whiteView.addSubview(closeBT)
        
        titleLabel.frame = CADipRectMake(frameSize.width/2-100/2, 0, 100, 88)
        whiteView.addSubview(titleLabel)
        
        okBT.frame = CADipRectMake(frameSize.width-120-spaceHeight, (88-60)/2, 120, 60)
        okBT.addTarget(self, action: #selector(FHPickerviewController.buttonClick(_:)), forControlEvents: .TouchUpInside)
        whiteView.addSubview(okBT)
        
        pickerView.frame = CADipRectMake(0, 88, 640, 300-88)
        whiteView.addSubview(pickerView)
        
        pickerView.delegate = self
        pickerView.dataSource = self
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func buttonClick(sender:UIButton){
        switch sender {
        case closeBT:
            break
        case okBT:
            break
        default:
            break
        }
    }
    
    // MARK: PickerViewDatasource
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{
        return 1
    }
    
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
        return rowtitle.count
    }
    
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
      print(rowtitle[row])
    }
    
    func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView{
        let la = UILabel()
        la.text = rowtitle[row]
        la.textAlignment = .Center
        return la
    }
}
